import ldap, { Client } from "ldapjs"
import { logger } from "../utils"

const client: Client = ldap.createClient({
  url: "ldap://10.2.220.1:389",
})

export default (useraccount: string, userpassword: string): Promise<string> => {
  return new Promise((resolve, reject) => {
    client.bind(useraccount, userpassword, (err) => {
      if (err) {
        logger.info(useraccount + " 验证失败")
        reject(err.toString())
      } else {
        logger.info(useraccount + " 验证成功")
        resolve("success")
      }
    })
  })
}
